Xi-Language Reference: Root Finding and Minimizing of Functions

    • find_root (Finds the root of a function)
    • minimize (Finds the minima of a function)

    find_root (Finds the root of a function)

    Parameters

              find_root ( func, x, tol = 1.0e-8, fcn_calls = 400 )
    
              Types: func                   Stmt
                     x                      double[]
                     tol                    double
                     fcn_calls              int
    

    Return

              [double[],double[]]  (root of \e\func\e\ and function values)
    

    Description

    The purpose of find_root is to find a zero of a system of n nonlinear functions in n variables by a modification of the powell hybrid method. The jacobian is calculated by a forward-difference approximation.

    In Xi the function func will be determined in a similar way like writing it down on a piece of paper. x< -> y : y=f (x). The parameter x contains an initial estimate of the solution vector. Termination occurs when the algorithm estimates that the relative error between x and the solution is at most tol. Termination also occurs when the number of calls to the function func is at least fcn_calls by the end of an iteration.

    Example

     (  1)>[x,f]=find_root([x->y: y=cos(x);],{2});
     Message: algorithm estimates that the relative error between x and the solution is at most tol in function find_root
     (  2)>print(x,f);
     <dblarr>
      1.570796327 
     <dblarr>
     6.123031769e-17 
     (  3)>print(find_root([x->y: y=cos(x);],{2, 4}));
     Message: algorithm estimates that the relative error between x and the
     solution is at most tol in function find_root
     <dblarr>
      1.570796327   4.71238898 
     (  4)>double[] f(double x[]) { return {sin(x[0]),3*cos(x[1]),cos(x[0]*x[2])};}
     Function f defined
     (  5)>print(find_root( [q->z : z=f(q);], {2,2,2}, \tol=1e-5,\fcn_calls=30));
     Message: algorithm estimates that the relative error between x and the
     solution is at most tol in function find_root
     <dblarr>
      3.141592654  1.570796327          1.5 
    

    Reference

    This function is based on the subroutine hybrd1 of MINPACK.
     c     argonne national laboratory. minpack project. march 1980.
     c     burton s. garbow, kenneth e. hillstrom, jorge j. more
     

    minimize (Finds the minima of a function)

    Parameters

              minimize ( func, x, tol = 1.0e-8, fcn_calls = 400 )
    
              Types: func                   Stmt
                     x                      double[]
                     tol                    double
                     fcn_calls              int
    

    Return

              [double[],double[]]  (minimum of \e\func\e\ and function values)
    

    Description

    Use the function minimize to find the minimum of the squares of m nonlinear functions in n variables by a modification of the levenberg-marquardt algorithm (To do this the jacobian is calculated by a forward-difference approximation).

    In Xi the function func will be determined in a similar way like writing it down on a piece of paper. x -> y : y=f (vector). The parameter x contains an initial estimate of the solution vector. Termination occurs when the algorithm estimates either that the relative error in the sum of squares is at most tol or that the relative error between x and the solution is at most tol. Termination also occurs when the number of calls to the function func is at least fcn_calls by the end of an iteration.

    Example

     (  1)>[x0,f0]=minimize( [ x->y : y=sin(x); ], {2} );
     Message: algorithm estimates that the relative error between x and the
     solution is at most tol in function minimize
     (  2)>print(x0, f0);
     <dblarr>
      3.141592654 
     <dblarr>
      1.224606354e-16 
     (  3)>print(minimize( [ x->y : y=sin(x); ], {2,5} ));
     Message: algorithm estimates that the relative error between x and the
     solution is at most tol in function minimize
     <dblarr>
      3.141592654  9.424777961 
     (  4)>double[] f(double x[]) { return {sin(x[0]),3*cos(x[1]),cos(x[0]*x[1])};}
     Function f defined
     (  5)>[x,f]=minimize( [q->z : z=f(q);], {1,1}, \tol=1e-5);
     Message: algorithm estimates that the relative error in the sum of squares
     is at most tol in function minimize
    (  6)>print(x,f);
     <dblarr>
      0.7711744677  1.597605977 
     <dblarr>
       0.6969779212 -0.08041931522   0.3323210158 
    

    Reference

    This function is based on the subroutine lmdif1 of MINPACK.
     c     argonne national laboratory. minpack project. march 1980.
     c     burton s. garbow, kenneth e. hillstrom, jorge j. more
     

    © 1995 by Bodo Junglas, Klaus Spanderen and Fabian Weis
    - Last revised: Wed Jun 19 16:58:32 1996